package com.example.mywebrtc;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import com.example.mywebrtc.util.WebRTCUtil;

import org.webrtc.EglBase;
import org.webrtc.RendererCommon;
import org.webrtc.SurfaceViewRenderer;

public class MainActivity extends AppCompatActivity {
    private SurfaceViewRenderer surfaceViewRenderer;
    private Button button;
    private EglBase eglBase;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        eglBase = EglBase.create();
        surfaceViewRenderer = (SurfaceViewRenderer) findViewById(R.id.renderer);
        //初始化SurfaceViewRenderer
        surfaceViewRenderer.init(eglBase.getEglBaseContext(), new RendererCommon.RendererEvents() {
            @Override
            public void onFirstFrameRendered() {

            }

            @Override
            public void onFrameResolutionChanged(int videoWidth, int videoHeight, int rotation) {

            }
        });
        surfaceViewRenderer.setScalingType(RendererCommon.ScalingType.SCALE_ASPECT_FILL);
        surfaceViewRenderer.setEnableHardwareScaler(true);
        surfaceViewRenderer.setZOrderMediaOverlay(true);
        button = (Button) findViewById(R.id.button);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                new WebRTCUtil(MainActivity.this, surfaceViewRenderer, eglBase);
            }
        });

    }


    @Override
    protected void onDestroy() {
        super.onDestroy();

    }
}